<?php
class keu_setup_detail_umk_model extends MY_Model {
	var $model = 'keu_setup_detail_umk';
	
	function GetJSON()
	{
		$ls_sql	= "	SELECT A.*, B.NAMA_COST_CENTER, A.KD_COST_CENTER||' - '||B.NAMA_COST_CENTER COST_CENTER, C.NAMA_COA
					FROM KEU_SETUP_DETAIL_UMK A JOIN SW_COST_CENTER B ON A.KD_COST_CENTER=B.ID_COST_CENTER_PK JOIN KEU_COA C ON A.ID_COA = C.ID_COA
					WHERE	UPPER(B.NAMA_COST_CENTER) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(A.KD_DETAIL_UMK) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(A.NAMA_DETAIL_UMK) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(A.KD_COST_CENTER) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(A.ID_COA) LIKE UPPER('%".post('keyword')."%')
							OR UPPER(C.NAMA_COA) LIKE UPPER('%".post('keyword')."%')
							
					ORDER BY ".(post('sort')=='' ? 'A.KD_DETAIL_UMK' : post('sort'))." ".(post('order')=='' ? 'ASC' : post('order'));
					
		return json_encode( $this->paging($ls_sql) );
	}
		
	function Add($arr_data){
		$this->db->insert('KEU_SETUP_DETAIL_UMK', $arr_data);
	}
	
	function Update($arr_data, $arr_rule){
		$this->db->update('KEU_SETUP_DETAIL_UMK', $arr_data, $arr_rule);
	}
	
	function GetSingle($as_code){
		$result = $this->db->get_where('KEU_SETUP_DETAIL_UMK', array('KD_DETAIL_UMK' => $as_code));
		if($result->num_rows() == 1){
			return $result->row_array();
		}else{
			return NULL;
		}
	}
	
	
	
	function DeleteSingle($as_code)
	{
		try {
			$this->db->delete('KEU_SETUP_DETAIL_UMK', array('KD_DETAIL_UMK' => $as_code));
			return '';
		} catch(Exception $e) {
			return $e->getMessage();
		}
	}
}
?>